<template>
    <div class="confirm-order">
        <div class="address-card b bor" @click="changeAddress">
            <img class="address-img" src="@/assets/images/address.png">
            <div class="right f14">
                <div class="consignee" v-if="false">
                    <span class="name">收货人:廖先生</span>
                    <span class="phone">12345678900</span>
                </div>
                <div v-else>
                    <span class="red">*</span>无
                </div>
                <span class="address" v-if="false">
                    地址:广东省广州市天河区广东省-广州市-天河区-棠下街道达善大街81号
                </span>
                <span v-else class="perfect">请完善地址信息</span>
            </div>
            <img class="more" src="@/assets/images/more.png">
        </div>
        <div class="goods b bor">
            <img v-if="orderData.goods_img" :src="getOtherImageUrl(orderData.goods_img)">
            <div class="detail">
                <span class="title bold">{{ orderData.setmeal_title }}</span>
                <span class="package f14 grey">套餐:{{ orderData.setmeal_title }}</span>
                <span class="time f14 grey">{{ orderData.lease_time }}</span>
                <span class="number f14 grey">数量:{{ orderData.amount }}</span>
            </div>
        </div>
        <DoubleMiniCard pay="付款方式" :payDetail="payDetailArr[orderData.pay_type]" mode="租赁方式"
            :modeDetail="orderData.pact_type">
        </DoubleMiniCard>
        <DownPayments class="b" :detailHandle="orderDetail" :payments="payments"></DownPayments>
        <div class="card f14 b bor">
            <div class="deposit flex">
                <div class="left">
                    <span>商品押金</span>
                </div>
                <span class="right-price">￥{{ orderData.foregift }}</span>
            </div>
            <div class="expire flex">
                <div class="left">
                    <span>预计到期买断尾款</span>
                    <img @click="show = true" src="@/assets/images/bangzhu.png">
                </div>
                <span class="right-price">￥{{ orderData.buyout_price }}</span>
            </div>
            <div class="way flex">
                <span>配送方式</span>
                <span class="right-price">{{ orderData.convey_type }}</span>
            </div>
        </div>
        <div class="attestation flex f14 bor">
            <span>实人认证</span>
            <span class="bold" @click="realName">未认证，请先完成实人认证></span>
        </div>
        <div class="email f14 bor b">
            <span>邮箱</span>
            <input type="email" v-model="email" placeholder="请输入您的个人邮箱">
        </div>
        <div class="remarks f14 bor b">
            <span>备注</span>
            <input type="text" v-model="remarks" placeholder="请输入您对本次订单的交易说明">
        </div>
        <div class="buy">
            <div class="head">
                <div class="agree" @click="agree = !agree" :class="{ active: agree }"></div>
                <div class="text">
                    <span class="f14">我同意调用数字证书签署</span>
                    <span class="f12" @click="agreement">"住赁服务协议及相关"</span>
                </div>
            </div>
            <div class="order-info flex">
                <div class="price">
                    <span class="f12">共{{ orderData.amount }}件,首期实付:</span>
                    <span class="val">￥{{ orderData.pay_rent ? orderData.pay_rent : orderData.first_rent }}</span>
                </div>
                <div class="btn" :class="{ active: agree }">
                    去免租
                </div>
            </div>
        </div>
        <div class="show" v-if="show" @click="show = false">
            <div class="box" @click.stop>
                <div class="head">
                    <span class="title bold">买断尾款</span>
                </div>
                <div class="close-btn" @click="show = false">
                    <Close></Close>
                </div>
                <div class="list">
                    <span class="f12">买断尾款为订单到期时买断商品所需付的金额</span>
                    <span class="f12">买断尾款=买断价-实付租金，如订单有冻结押金，冻结押金可抵扣买断尾款</span>
                    <span class="f12">优惠金额仅限于抵扣租金，不能用于抵扣买断价格</span>
                </div>
            </div>
        </div>
        <loading v-if="!payments.total_rent"></loading>
    </div>
</template>
<script>
import Close from "@/components/Close.vue";
import DownPayments from "@/components/Order/DownPayments.vue";
import DoubleMiniCard from "@/components/Order/DoubleMiniCard.vue";
export default {
    name: "ConfirmOrder",
    components: {
        Close,
        DownPayments,
        DoubleMiniCard
    },
    data() {
        return {
            email: "",
            remarks: "",
            agree: false,
            show: false,
            payDetailArr: ["智能合同代扣", "⽀付宝预授权", "花呗分期⽀付"],
            orderData: {},
            payments: {
                pay_rent: "",   //⾸期实付⾦额 
                total_rent: "", //总租⾦ 
                total_num: "",  //总租期 
                first_rent: "", //⾸期租⾦ 
                last_rent: "",  //剩余租⾦
                last_term: "",  //剩余租期
                activity_title: "",//活动标题 
                pay_code: "",//优惠抵扣
            },
        }
    },
    created() {
        this.getOrderInfo();
    },
    methods: {
        changeAddress() {
            this.$router.push({ name: "address" });
        },
        getOrderInfo() {
            const query = this.$route.query;
            this.$sendPost("Order/confirmOrder", query)
                .then(res => {
                    const { data } = res.data;
                    if (res.data.status === 200) {
                        this.orderData = data;
                        for (let key in this.payments) {
                            this.payments[key] = this.orderData[key]
                        }
                    } else if (res.data.status === 300) {
                        this.$toast(res.data.msg);
                        setTimeout(() => {
                            this.$router.push({ name: "login" })
                        }, 2000)
                    }
                    console.log(data);
                })
        },
        orderDetail() {
            const query = this.$route.query;
            query.goods_img = this.orderData.goods_img;
            this.$router.push({ name: "order-detail", query })
        },
        realName() {
            this.$router.push({ name: "real-name" })
        },
        agreement() {
            this.$router.push({ name: "agreement" })
        }
    }
}
</script>
<style lang="scss" scoped>
.grey {
    color: #939393;
}

.flex {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.bor {
    border-radius: 8px;
    overflow: hidden;
}

.confirm-order {
    padding: 15px;
    background-color: #f7f7f7;

    .address-card {
        width: 100%;
        height: 80px;
        display: flex;
        padding: 20px;
        align-items: center;
        background-color: white;
        position: relative;

        .address-img {
            width: 17px;
            margin-right: 15px;
            object-fit: contain;
        }

        .right {
            .consignee {
                display: flex;
                align-items: center;
                justify-content: space-between;
                margin-bottom: 10px;
            }

            .perfect {
                color: #9c9c9c;
            }
        }

        .more {
            position: absolute;
            top: 50%;
            right: 20px;
            width: 8px;
            object-fit: contain;
            transform: translateY(-50%);
        }

    }

    .goods {
        height: 140px;
        background-color: white;
        display: flex;

        img {
            height: 140px;
            width: 140px;
        }

        .detail {
            width: 205px;
            padding: 10px;
            padding-left: 0;
            display: flex;
            flex-direction: column;

            .package {
                margin-top: 15px;
                overflow: hidden;
                white-space: nowrap;
                text-overflow: ellipsis;
            }

            .time {
                margin: 5px 0;
            }
        }
    }

    .card {
        background-color: white;

        .right-price {
            color: #989898;
        }

        .flex {
            padding: 15px 10px;
        }

        .expire {
            border-bottom: 1px solid #f0f0f0;
            border-top: 1px solid #f0f0f0;

            .left {
                display: flex;
                align-items: center;

                img {
                    margin-left: 5px;
                    width: 15px;
                }
            }
        }
    }

    .attestation {
        padding: 15px 10px;
        background-color: white;
        margin-bottom: 5px;

        span {
            &:nth-of-type(2) {
                color: #f40508;
            }
        }
    }

    .email,
    .remarks {
        padding: 15px 10px;
        background-color: white;
        display: flex;

        span {
            display: inline-block;
            width: 13%;
        }

        input {
            margin-left: 10px;
            border: 0;
            outline: 0;
            height: 100%;
            width: 87%;
        }
    }

    .remarks {
        margin-bottom: 80px;

    }

    .buy {
        width: 100vw;
        height: 90px;
        position: fixed;
        bottom: 0;
        left: 0;
        background-color: white;
        padding: 10px 15px;

        .head {
            display: flex;

            .agree {
                width: 20px;
                height: 20px;
                border-radius: 50%;
                border: 1px solid #e2e2e2;
                margin-right: 5px;

                &.active {
                    border: 1px solid transparent;
                    background-size: 100% 100%;
                    background-repeat: no-repeat;
                    background-image: url("@/assets/images/xuanzhong.png");
                }
            }

            .text {
                .f12 {
                    color: #3f8dd5;
                }
            }
        }

        .order-info {
            padding: 10px 0;

            .price {
                .val {
                    color: #f05251;
                }
            }

            .btn {
                padding: 10px 35px;
                border-radius: 20px;
                color: white;
                background-color: #c1c1c1;

                &.active {
                    background-color: #f05251;
                }
            }
        }
    }

    .show {
        width: 100vw;
        height: 100vh;
        background-color: rgba(0, 0, 0, .3);
        position: fixed;
        top: 0;
        left: 0;
        display: flex;
        align-items: center;
        justify-content: center;

        .box {
            background-color: white;
            width: 70vw;
            height: 200px;
            padding: 20px 10px;
            border-radius: 6px;
            position: relative;

            .head {
                margin-bottom: 15px;
                text-align: center;
            }

            .close-btn {
                position: absolute;
                right: 15px;
                top: 15px;
            }

            .list {
                color: #9b9b9b;

                span {
                    &:nth-of-type(2) {
                        margin: 20px 0;
                    }
                }
            }
        }
    }
}
</style>